package com.ruoyi.dictionaries.controller;

import java.util.List;


import com.ruoyi.common.utils.uuid.IdUtils;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dictionaries.domain.CertificateType;
import com.ruoyi.dictionaries.service.ICertificateTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 证件类型Controller
 *
 * @author gdslovehy
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/dictionaries/gertificatetype")
public class CertificateTypeController extends BaseController
{
    @Autowired
    private ICertificateTypeService certificateTypeService;

    /**
     * 查询证件类型列表
     */
    //@PreAuthorize("@ss.hasPermi('dictionaries:gertificatetype:list')")
    @GetMapping("/list")
    public TableDataInfo list(CertificateType certificateType)
    {
        startPage();
        List<CertificateType> list = certificateTypeService.selectCertificateTypeList(certificateType);
        return getDataTable(list);
    }

    /**
     * 导出证件类型列表
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:gertificatetype:export')")
    @Log(title = "证件类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CertificateType certificateType)
    {
        List<CertificateType> list = certificateTypeService.selectCertificateTypeList(certificateType);
        ExcelUtil<CertificateType> util = new ExcelUtil<CertificateType>(CertificateType.class);
        util.exportExcel(response, list, "证件类型数据");
    }

    /**
     * 获取证件类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:gertificatetype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(certificateTypeService.selectCertificateTypeById(id));
    }

    /**
     * 新增证件类型
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:gertificatetype:add')")
    @Log(title = "证件类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CertificateType certificateType)
    {
        certificateType.setId(IdUtils.fastSimpleUUID());
        return toAjax(certificateTypeService.insertCertificateType(certificateType));
    }

    /**
     * 修改证件类型
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:gertificatetype:edit')")
    @Log(title = "证件类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CertificateType certificateType)
    {
        return toAjax(certificateTypeService.updateCertificateType(certificateType));
    }

    /**
     * 删除证件类型
     */
    @PreAuthorize("@ss.hasPermi('dictionaries:gertificatetype:remove')")
    @Log(title = "证件类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(certificateTypeService.deleteCertificateTypeByIds(ids));
    }
}
